"""school_assistant_api URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static

from django.views import static as st   ##新增
from django.conf import settings   ##新增
from django.conf.urls import url,include    ##新增
from rest_framework import routers
from rest_framework.documentation import include_docs_urls
from rest_framework.authtoken.views import obtain_auth_token

from django.conf.urls.static import static
from school_assistant_api.settings import MEDIA_URL, MEDIA_ROOT
from users import views as UsersViews

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'^static/(?P<path>.*)$', st.serve,
        {'document_root': settings.STATIC_ROOT}, name='static'),
    url(r'^media/(?P<path>.*)$', st.serve, 
        {'document_root': settings.MEDIA_ROOT})
]

router = routers.DefaultRouter()

# router.register(r'', .UsersViews, basename='')

router.register(r'groups', UsersViews.GroupViewSet, basename='groups')
router.register(r'group-option', UsersViews.GroupOptionViewSet, basename='group-option')
router.register(r'users', UsersViews.UserViewSet, basename='users')
router.register(r'user-option',UsersViews.UserOptionViewSet, basename='userextension-option')
router.register(r'score',UsersViews.ScoreViews, basename='score')
router.register(r'role',UsersViews.RoleViews, basename='role')
router.register(r'role-option',UsersViews.RoleOptionViews, basename='role-option')
router.register(r'grade',UsersViews.GradeViews, basename='grade')
router.register(r'grade-option',UsersViews.GradeOptionViews, basename='grade-option')
router.register(r'course',UsersViews.CourseViews, basename='course')
router.register(r'course-option',UsersViews.CourseOptionViews, basename='course-option')
router.register(r'homework',UsersViews.HomeworkViews, basename='homework')
router.register(r'homework-option',UsersViews.HomeworkOptionViews, basename='homework-option')
router.register(r'homeworkchecktask',UsersViews.HomeworkCheckTaskViews, basename='homeworkchecktask')
router.register(r'homeworkchecktask-option',UsersViews.HomeworkCheckTaskOptionViews, basename='homeworkchecktask-option')
router.register(r'userportrait',UsersViews.UserPortraitViews, basename='userportrait')
router.register(r'userportrait-option',UsersViews.UserPortraitOptionViews, basename='userportrait-option')
router.register(r'portrait',UsersViews.PortraitViews, basename='portrait')
router.register(r'portrait-option',UsersViews.PortraitOptionViews, basename='portrait-option')
router.register(r'images',UsersViews.ImagesViews, basename='images')
router.register(r'images-option',UsersViews.ImagesOptionViews, basename='images-option')
router.register(r'userimage',UsersViews.UserImageViews, basename='userimage')
router.register(r'userimage-option',UsersViews.UserImageOptionViews, basename='userimage-option')
router.register(r'files',UsersViews.FilesViews, basename='files')
router.register(r'files-option',UsersViews.FilesOptionViews, basename='files-option')
router.register(r'userfile',UsersViews.UserFileViews, basename='userfile')
router.register(r'userfile-option',UsersViews.UserFileOptionViews, basename='userfile-option')

urlpatterns = [
    path('', include(router.urls)),
    path('admin/', admin.site.urls),
    path('docs/', include_docs_urls(title="校园助手")),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),  
    path('login/', UsersViews.LoginView.as_view(), name='my_token'),
    # path('logout/', UsersViews.LogoutView.as_view()),
] + static(MEDIA_URL, document_root=MEDIA_ROOT)
